package com.zsc.rediscli.sentinel;

import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisSentinelPool;

import java.util.HashSet;
import java.util.Set;

public class RedisSentinel {

    public static void main(String[] args) {
        //获取sentinel的所有节点
        Set<String> sentinels = new HashSet<>();
        sentinels.add("192.168.56.108:26379");
        sentinels.add("192.168.56.108:26380");
        sentinels.add("192.168.56.108:26381");
        //jedis实现对redis sentinel的客户端连接
        JedisSentinelPool jedisSentinelPool = new JedisSentinelPool("mymaster",sentinels);
        Jedis jedis = null;
        try{
            jedis = jedisSentinelPool.getResource();
//            jedis.set("hello","world");
            String hello = jedis.get("hello");
            System.out.println(hello);
        }catch (Exception e){
            e.printStackTrace();
        }finally {
            if (jedis != null){
                jedis.close();
            }
        }
    }


}
